package com.example.controller;

import com.example.domain.vto.Result;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    //匿名可访问
    @GetMapping("/test1")
    public Result test1() {
        return Result.ok("匿名可访问");
    }

   //登录才能访问
    @GetMapping("/test2")
    public Result test2() {
        return Result.ok("登录才能访问");
    }

    //登录且拥有admin角色才能访问
    @PreAuthorize("hasRole('admin')")
    @GetMapping("/test3")
    public Result test3() {
        return Result.ok("登录且拥有admin角色才能访问");
    }

    //登录且拥有select权限才能访问
    @PreAuthorize("hasAuthority('select')")
    @GetMapping("/test4")
    public Result test4() {
        return Result.ok("登录且拥有select权限才能访问");
    }

    //登录且拥有select权限和admin角色才能访问
    @PreAuthorize("hasAuthority('select') and hasRole('admin')")
    @GetMapping("/test5")
    public Result test5() {
        return Result.ok("登录且拥有select权限和admin角色才能访问");
    }

    //登录且拥有select权限和ad角色才能访问
    @PreAuthorize("hasAuthority('select') and hasRole('ad')")
    @GetMapping("/test6")
    public Result test6() {
        return Result.ok("登录且拥有select权限和ad角色才能访问");
    }



}
